<!-- Bojan Karlas -->	

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <link rel="shortcut icon" href="favicon.ico"/>
        <title>Поклони</title>
        <link href="style.css" rel="stylesheet" type="text/css" media="screen" />
        <script type="text/javascript" src="jquery.js"></script>
        <script type="text/javascript">
            function anketaJeZavrsena() {
                alert("Zavrsena");
            }

            function gup( name )
            {
                name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
                var regexS = "[\\?&]"+name+"=([^&#]*)";
                var regex = new RegExp( regexS );
                var results = regex.exec( window.location.href );
                if( results == null )
                    return "";
                else
                    return results[1];
            }

            function searchBase() {
                var pretraga = encodeURIComponent( $("#txtSearch").val());
                var vrsta = gup('vrsta');
	
                if (vrsta != "") vrsta = "&vrsta=" + vrsta;
                if (pretraga != "") $("#content-main").load("insert/prikaz_pretrage.php?mod=rec&rec=" + pretraga + vrsta);
                else $("#content-main").load("insert/prikaz_pretrage.php?mod=sve" + vrsta);
            }

            function filterBase(pol, starost, idTip) {
	
                //$("#content-main").text("Pol: " + pol + ";  Starost: " + starost + ";  Tip: " + idTip);
                //alert("Pol: " + pol + ";  Starost: " + starost + ";  Tip: " + idTip);
                if (idTip != undefined && idTip != "svi") {
		
                    $("#content-main").load("insert/prikaz_pretrage.php?vrsta=pokloni&mod=filter&tip=" + idTip);
                } else if ((pol != undefined && pol != "svi") || (starost != undefined && starost != "svi")) {
                    $("#content-main").load("insert/prikaz_pretrage.php?vrsta=pokloni&mod=filter&pol=" + pol + "&starost=" + starost);
                } else {
                    var vrsta = gup('vrsta');
                    $("#content-main").load("insert/prikaz_pretrage.php?mod=sve&vrsta=" + vrsta);
                }
            }

            $(document).ready(function(){
                $("#btnSearch").click(searchBase);
                $("#txtSearch").keypress(function(e) {
                    if(e.keyCode == 13) {
                        searchBase();
                    }
                });
            });
        </script>

        <?php
        session_start();
        if (!isset($_SESSION['id'])) {
            $_SESSION['tip'] = 'N';
            $_SESSION['id'] = '2';
        }
        include ("upisi_url.php");
        ?>
        <?php header("Content-type: text/html; charset=utf-8");
        ?>
    </head>

    <body>

        <div id="wrapper">

<?php include("insert/head.php"); ?>

            <div id="content">


                <div>
                    <input type="text" id="txtSearch"  size="60" style="height:20px; margin:0px; margin-left:40px"/>
                    <input type="button" id="btnSearch" class="button" value="Претражи"
                           style="padding-bottom:1px; padding-top:1px; font-size:18px; margin-top:1px; vertical-align:middle" />
                </div>
                <br/>
                <div id="content-main" style="min-height:600px">
<?php include("insert/prikaz_pretrage.php"); ?>

                </div>

<?php
        if (isset($_SESSION['tip']) && ($_SESSION['tip'] == 'F' || $_SESSION['tip'] == 'P'))
            $vezaDodaj = "dodaj_poklon.php";
        else
            $vezaDodaj = "registracija_posetioca.php";
?>

                <ul id="content-side">
                    <div style="display:block; height:100px; text-align:center">
<?php echo '<a class="button" href="' . $vezaDodaj . '">'; ?>
                        <img src="images/yellow-plus.png" style="float:left; position:relative; left:-10px; margin:-3px"/>
                        <span style="font-size:30px">Додај</span><br/>
                	поклон
                        </a>
                    </div>

<?php if ($_SESSION['tip'] == 'A') { ?>
                    <li id="adminpanel">


<?php include("insert/adminpanel.php"); ?>
                    </li>

<?php } ?>

<?php if (isset($_GET["vrsta"]) && $_GET["vrsta"] == "pokloni") { ?>
                    <li>
                        <div class="dashes-top"></div>
                        <div class="dashes-bottom"></div>
                        <h3> Филтрирање претраге </h3>

                        <script type="text/javascript">
                            var licnostPol = "svi", licnostStarost = "svi", licnostTip = "svi";
					
                            function tipoviLoaded() {
                                $(".elemTipLic").click(function(){
                                    var thisSelected = $(this).hasClass("selected");
							
                                    $(".elemTipLic").removeClass("selected");
                                    if (thisSelected == false) {
                                        $(this).addClass("selected");
                                        licnostTip = this.id;
                                        licnostTip = licnostTip.substring(licnostTip.indexOf('_')+1);
								
                                    } else licnostTip = "svi";
							
                                    filterBase(null, null, licnostTip);
                                });
                            }
					
                            $(document).ready(function(){
						
						
						
                                $(".btnPol").click(function(){
                                    var thisSelected = $(this).hasClass("selected");
							
							
							
                                    $(".btnPol").removeClass("selected");
                                    if (thisSelected == false) {
                                        $(this).addClass("selected");
                                        licnostPol = this.id;
                                        licnostPol = licnostPol.substr(licnostPol.length-1, 1);
                                    } else licnostPol = "svi";
                                    $("#listaTipova").load("insert/prikazitipove.php?pol=" + licnostPol + "&starost=" + licnostStarost, null,tipoviLoaded);
							
                                    filterBase(licnostPol, licnostStarost);
                                });
						
                                $(".btnStarost").click(function(){
                                    var thisSelected = $(this).hasClass("selected");
							
                                    $(".btnStarost").removeClass("selected");
                                    if (thisSelected == false) {
                                        $(this).addClass("selected");
                                        licnostStarost = this.id;
                                        licnostStarost = licnostStarost.substr(licnostStarost.length-1, 1);
                                    } else licnostStarost = "svi";
							
                                    $("#listaTipova").load("insert/prikazitipove.php?pol=" + licnostPol + "&starost=" + licnostStarost, null,tipoviLoaded);
                                    filterBase(licnostPol, licnostStarost);
                                });
						
                                tipoviLoaded();
						
                                $("#btnPopuniAnketu").click(function() {
                                    $("#popupCont").css("visibility", "visible");
                                    $("#contAnketa").load("anketa.php?pol=" + licnostPol + "&starost=" + licnostStarost + "&svrha=pretraga");
                                });
						
						
                            });
					
                        </script>

                        <br/>Пол:<br/>
                        <div class="barbutton btnPol" id="polM">Мушко</div>
                        <div class="barbutton btnPol" id="polZ">Женско</div>
                        <br/>Старост:<br/>
                        <div class="barbutton btnStarost" id="starostD">Дете</div>
                        <div class="barbutton btnStarost" id="starostA">Адолесцент</div>
                        <div class="barbutton btnStarost" id="starostO">Одрасла особа</div>
                        <br/>Тип личности:<br/>

                        <div class="scroll-container" id="listaTipova" style="height:300px">
<?php include("insert/prikazitipove.php") ?>
                        </div>
                        <span style="text-align:right; display:block">
                            Нисте сигурни који тип?<br/>
                            <div id="btnPopuniAnketu" class="button" style="cursor:pointer">Попуни анкету</div></span><br/>
                    </li>
<?php } ?>
                </ul>

            </div>


        </div>


        <div id="popupCont" class="popup-container" style="visibility:hidden">
            <div class="popup" style="width:400px; height:150px">
                <div id="dashes-top" style="display:block; width:90%"></div>
                <div id="dashes-bottom" style="display:block; width:90%"></div>
                <div id="contAnketa">
                </div>
            </div>
        </div>

    </body>
</html>